﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ServiceLayer;
using BLL;
using DAL;
using DAL.Mappers;

namespace POCFrw
{
    class Program
    {
        static void Main(string[] args)
        {

            //DAL.Helpers.StoredProceduresHelper.sqf_stp_insert_dettagli_scommessa(0, 0, DAL.Helpers.T4.ToParameter(0, 0, 0, true, true));

            //DAL.Helpers.StoredProceduresHelper.bwin_stp_insert_game_session("", "", "", "", "", "", "", "", DAL.Helpers.T5.ToParameter(DateTime.Now, "", "", "", 0, ""), DAL.Helpers.T5.ToParameter(DateTime.Now, "", "", "", 0, ""), 0, 0, 0);

            User1 user1 = new User1() { Id=100, Name = "pppo" };
            User1 user2 = new User1() { Name="pppo" };

            BetpointAdvancedEntities ctx = new BetpointAdvancedEntities();
            var users1 = from x in ctx.utenti where x.id_utente == 1 select x;
            var users = ToDTO(ctx.utenti.Where(x => x.id_utente == 1));
            var users2 = ToDTO(from x in ctx.utenti where x.id_utente == 1 select x);
            var utenti1 = FromDTO(users2.ToList());

            UserMapper um = new UserMapper();
            var ppp1 = um.ToDTO(ctx.utenti.Where(x => x.id_utente == 1));
            var ppp2 = um.FromDTO(ppp1);

            //
            IAuthentication obj = UserAuthentication.GetInstance();

            User user = new User() { Id = 2116 };
            BLL.User userAA = obj.GetUser(user);

            User userq = new User() { Id = 2075 };
            BLL.User userQQ = obj.GetUser(userq);

            IAuthentication pvrObj = PVRAuthentication.GetInstance("PVRAuthentication");
            BLL.User userQQ1 = pvrObj.GetUser(userq);

            UserAuthentication pp = new UserAuthentication();
            BLL.User userQQ2 = pp.GetUser(userq);

            User user33 = new User() { Name = "aaaaaaaaaaaaa" };
            obj.ValidateUser(user33);

            obj.ValidateUser(user33);
        }

        static Func<utenti, User> Map(utenti utente)
        {
            Func<utenti, User> retValue = null;

            User u = new User();
            u.Name = utente.username;
            u.Surname = utente.username;

            return retValue;
        }

        public static IQueryable<User1> ToDTO(IQueryable<utenti> objects)
        {
            return
                from x in objects
                select new User1()
                {
                    Name = x.username
                };
        }

        public static List<utenti> FromDTO(List<User1> objects)
        {
            List<utenti> retValue = new List<utenti>(objects.Count);

            objects.ForEach(x => { retValue.Add(new utenti() { username = x.Name }); });

            return retValue;
        }

        public void TestStoredProcedures()
        {
            //SqlCommand cmd = StoredProceduresHelper.ReportDirezionale(null, null, null, null, null, null, null, null, null, null, null);

            //using (StoreProcedureExecutor spe = new StoreProcedureExecutor(cmd))
            //{
            //    var pp = spe.ExecuteQueryObjectResult<ReportDirezionale_Result, GestionePolveriEntities>();

            //    long nn = pp.Count();
            //}
        }
    }
}
